package com.six.firstpage.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Zone;
import com.six.core.vo.Result;
import com.six.firstpage.service.ZoneService;
import com.six.firstpage.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 10:30
 * @Description:
 */
@Api(value = "firstpage/api/zone", tags = {"专区管理前端Api"})
@RestController
@RequestMapping("firstpage/api/zone")
//@CrossOrigin
public class ApiZoneController {

    @Autowired
    private ZoneService zoneService;

    @GetMapping("getAllZone")
    public Result getAllZone(){
        List<Zone> allZone = zoneService.getAllZone();
        return new Result(2000,"查询所有专区成功",allZone);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SearchVo", name = "searchVo", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "current", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("getZoneByName/{current}/{pageSize}")
    public Result getZoneByName(@RequestBody SearchVo searchVo, @PathVariable Integer current, @PathVariable Integer pageSize ){
        Page<Zone> zoneByName = zoneService.getZoneByName(searchVo.getTitle(), searchVo.getStatus(), current, pageSize);
        return new Result(200,"查询专区成功",zoneByName);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Zone", name = "zone", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addZone")
    public Result addZone(@RequestBody Zone zone){
        Integer integer = zoneService.addZone(zone);
        if (integer>0){
            return new  Result(2000,"添加专区成功");
        }
        return new  Result(5000,"添加专区失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Zone", name = "zone", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateZone")
    public Result updateZone(@RequestBody Zone zone){
        Integer integer = zoneService.updateZone(zone);
        if (integer>0){
            return new  Result(2000,"修改专区成功");
        }
        return new  Result(5000,"修改专区失败");
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delZone/{id}")
    public Result delZOne(@PathVariable Integer id){
        Integer integer = zoneService.delZone(id);
        if (integer>0){
            return new  Result(2000,"删除专区成功");
        }
        return new  Result(5000,"删除专区失败");
    }
}
